﻿using System;
using System.IO;
using System.Net;
using System.Text;
//using CrawlerCore;
using WapCrawlerCore;
using WapCrawlerCore.WapCrawler;
using WapCrawlerLib;
using System.Web;

namespace WapCrawler
{
    public partial class frmCrawlerWaps : System.Web.UI.Page
    {
        private int _index = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            
            
        }

        public void AlomobSample()
        {
            //IWapSite wap = new AlomobWapSite((int)EnumWapSite.Alomob);
            //wap.GetItem(@"game.php?cat_id=1&game_id=1992&lg=en", "Transformers- Revenge of the Fallen");
            //wap.GetItem(@"game.php?cat_id=7&game_id=1991&lg=en", "Extreme ATV");
            //wap.GetItem(@"game.php?cat_id=10&game_id=1990&lg=en", "Battle of Large Tank");
            //wap.GetItem(@"game.php?cat_id=7&game_id=1989&lg=en", "Tezz-The Official Movie Game");
            //wap.GetItem(@"game.php?cat_id=9&game_id=1988&lg=en", "Kingdom of Grain");
            //wap.GetItem(@"game.php?cat_id=7&game_id=1987&lg=en", "Galaxy_Racers");
            //wap.GetItem(@"game.php?cat_id=10&game_id=1986&lg=en", "Exodus");
            //wap.GetItem(@"game.php?cat_id=10&game_id=1985&lg=en", "Metal Slug 2013");
            //wap.GetItem(@"game.php?cat_id=7&game_id=1983&lg=en", "Fast and Furious - Adrenalin","","");
        }

        public void WapTaiGameSample()
        {
            //IWapSite wap = new WapTaiGameWapSite((int)EnumWapSite.Waptaigame);
            //wap.GetItem(@"2012/10/vua-bai-phien-ban-253-cap-nhat-131012.html", "Vua bài phiên bản 2.5.3 cập nhật 13/10/12","","");
        }

        public void WapTaiSample()
        {
            WapSiteBase wap = new WapTaiWapSite((int)EnumWapSite.Waptai);
            wap.GetItem(@"game/cang-than-chi-no-viet-hoa-crack", TopicCrawlerDropDownList.SelectedItem.Text);
            //wap.GetItem(@"game/silent-hill-3-doi-cam-lang-viet-hoa", "Tải Game Mobile Silent hill 3 đồi câm lặng việt hoá","","");
        }

        public void HayDaySample(string pageUrl, string postTitle)
        {
            //IWapSite wap = new GauPandaWapsite((int)EnumWapSite.Hayday);
            //string pageUrl = "game-hay/game-online.html?page=5&ref=hayday";
            //string postTitle = "Chiến Thần Online - Phiên bản Thánh Chiến Olympia";
            //wap.Test(pageUrl, postTitle);

            WapSiteBase wap = new GauPandaWapsite((int)EnumWapSite.Hayday);
            //string pageUrl = "game-hay/game-online.html?page=1&ref=hayday";
            //string postTitle = "Vườn Thủy Cung - Xứ Sở Thần Tiên";
            wap.Test(pageUrl, postTitle);
            
            //wap.GetItem(@"game-hay/tru-than-online-2012.html?ref=hayday", "Tru Thần Online 2012", "Game Tiên hiệp có tạo hình nhân vật dễ thương cùng với những tính năng vô cùng đặc sắc, độc đáo. Tru Thần Online mang lại cho game thủ những trải nghiệm thú vị.", "http://gaupanda.hayday.mobi/static/images/2012/11/09/53x53_d156cca7b9cb168b12eca8f5269d15b01352457178_truthan-nq8.png");
            //wap.GetItem(@"game-hay/thanh-cat-tu-han-dung-binh-thien-ha-1351052754.html?ref=hayday", "Thành Cát 2 - Game Online 3D", "", "");
        }

        protected void btnTestPage_Click(object sender, EventArgs e)
        {
            WapSiteBase wap = GeneralWap.InitWapSite(int.Parse(WapCrawlerDropDownList.SelectedValue));
            //string pageUrl = "game-hay/game-online.html?page=1&ref=hayday";
            //string postTitle = "Vườn Thủy Cung - Xứ Sở Thần Tiên";
            wap.Test(txtTestPageUrl.Text, txtTestTitle.Text);
        }

        

        private bool isStart = false;
        protected void btnStartCrawler_Click(object sender, EventArgs e)
        {
            isStart = true;
            int wapCrawlerId = int.Parse(WapCrawlerDropDownList.SelectedValue);
            int topicCrawlerId = int.Parse(TopicCrawlerDropDownList.SelectedValue);
            WapSiteBase wap = WapCrawlerCore.GeneralWap.InitWapSite(wapCrawlerId);
            wap.isAllowUpdate = CheckBoxAllowUpdate.Checked;
            wap.StartCrawler(topicCrawlerId);
        }

        
        protected void btnStopCrawler_Click(object sender, EventArgs e)
        {
            isStart = false;
        }

        protected void WapCrawlerDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtTestWapUrl.Text = WapCrawlerDropDownList.SelectedItem.Text;
        }
    }
}